package com.sylar.happygps;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MapActivity extends Activity implements OnClickListener {
	private Button btn_edit;
	private View layout_map_nav_bottom;
	private GestureDetector mGestureDetector;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.map);

		Button btn_title_left = (Button) findViewById(R.id.btn_title_left);
		btn_title_left.setVisibility(View.VISIBLE);
		btn_title_left.setText("约会地选择方式");
		btn_title_left.setOnClickListener(this);

		Button btn_help = (Button) findViewById(R.id.btn_help);
		btn_help.setVisibility(View.VISIBLE);
		btn_help.setOnClickListener(this);

		btn_edit = (Button) findViewById(R.id.btn_edit);
		btn_edit.setVisibility(View.VISIBLE);
		btn_edit.setText("退出编辑");
		btn_edit.setOnClickListener(this);

		Button btn_to_turo_info = (Button) findViewById(R.id.btn_to_turo_info);
		btn_to_turo_info.setOnClickListener(this);
		Button btn_edit_turo_info = (Button) findViewById(R.id.btn_edit_turo_info);
		btn_edit_turo_info.setOnClickListener(this);
		Button btn_edit_road_info = (Button) findViewById(R.id.btn_edit_road_info);
		btn_edit_road_info.setOnClickListener(this);
		Button btn_edit_road_attr = (Button) findViewById(R.id.btn_edit_road_attr);
		btn_edit_road_attr.setOnClickListener(this);

		Button btn_mapopt = (Button) findViewById(R.id.btn_mapopt);
		btn_mapopt.setOnClickListener(this);
		
		Button btn_mapopt1 = (Button) findViewById(R.id.btn_mapopt1);
		btn_mapopt1.setOnClickListener(this);

		TextView tv_title_name = (TextView) findViewById(R.id.tv_title_name);
		tv_title_name.setText("地图");

		mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
			@Override
			public void onLongPress(MotionEvent e) {
				MapOptions();
				super.onLongPress(e);
			}
		});

		layout_map_nav_bottom = findViewById(R.id.layout_map_nav_bottom);
		
		
		//google地图图层
		View layout_googlemap = findViewById(R.id.layout_googlemap);
		
		
		//自己的地图图层
		View layout_mymap = findViewById(R.id.layout_mymap);

	}

	private void MapOptions() {
		Intent intent = new Intent(this, MapOptions.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(intent);
	}
	private void MapOptions1() {
		Intent intent = new Intent(this, MapOptionOther.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(intent);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return mGestureDetector.onTouchEvent(event);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_title_left:
			finish();
			break;
		case R.id.btn_help:
			toHelpActivity();
			break;
		case R.id.btn_edit:
			if (btn_edit != null) {
				if (btn_edit.getText().equals("编辑")) {
					btn_edit.setText("退出编辑");
					if (layout_map_nav_bottom != null) {
						layout_map_nav_bottom.setVisibility(View.VISIBLE);
					}
				} else if (btn_edit.getText().equals("退出编辑")) {
					btn_edit.setText("编辑");
					if (layout_map_nav_bottom != null) {
						layout_map_nav_bottom.setVisibility(View.GONE);
					}
				}
			}
			break;
		case R.id.btn_to_turo_info:
			toTuroInfo();
			break;
		case R.id.btn_edit_turo_info:
			toTuroEdit();
			break;
		case R.id.btn_edit_road_info:
			toRoadInfoEdit();
			break;
		case R.id.btn_edit_road_attr:
			toRoadAttrEdit();
			break;

		case R.id.btn_mapopt:
			MapOptions();
			break;
			
		case R.id.btn_mapopt1:
			MapOptions1();
			break;
		}
	}

	private void toTuroInfo() {
		Intent intent = new Intent(this, TourInfoActivity.class);
		startActivity(intent);
	}

	private void toTuroEdit() {
		Intent intent = new Intent(this, TourEditActivity.class);
		startActivity(intent);
	}
	
	private void toRoadInfoEdit() {
		Intent intent = new Intent(this, RoadInfoEditActivity.class);
		startActivity(intent);
	}
	private void toRoadAttrEdit() {
		Intent intent = new Intent(this, RoadAttrEditActivity.class);
		startActivity(intent);
	}

	private void toHelpActivity() {
		Intent intent = new Intent(this, HelpActivity.class);
		intent.putExtra("helptype", HelpActivity.TYPE_MAP_HELP);
		startActivity(intent);
	}
}
